﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Calcite.Classes;

namespace Calcite.Classes
{
    public partial class EditColumnsDialog : Form
    {
        public List<ColumnHeaderData> EditedValues = new List<ColumnHeaderData>();
        public EditColumnsDialog(WorksheetGridView worksheetGridView)
        {
            int i;

            InitializeComponent();

            //DataColumnCollection cols = ((Worksheet)this.ParentForm).rawDataGridView.data.Columns;

            i = 0;
            foreach (DataColumn tmpCol in worksheetGridView.data.Columns)
            {

                string[] rowData = {
                    tmpCol.ExtendedProperties["Column Title"].ToString(),
                    tmpCol.ExtendedProperties["Units"].ToString()
                                   };
                this.dataGridView1.Rows.Add(rowData);
                this.dataGridView1.Rows[i].HeaderCell.Value = tmpCol.ColumnName;
                i = i + 1;
            }
            
        }

        private void OKButton_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in this.dataGridView1.Rows)
            {
                ColumnHeaderData tmpData = new ColumnHeaderData();
                tmpData.DataColumnHeader = row.HeaderCell.Value.ToString();
                tmpData.ViewableHeader = row.Cells[0].Value == null ? "-" : row.Cells[0].Value.ToString();
                tmpData.Units = row.Cells[1].Value == null ? "-" : row.Cells[1].Value.ToString();
                this.EditedValues.Add(tmpData);
            }
            this.DialogResult = DialogResult.OK;
            
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            
        }



    }

    public struct ColumnHeaderData 
    // Simple struct for returning the data
    {
        public string DataColumnHeader, ViewableHeader, Units;
    }
}
